#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <string.h>

void handler(int signum){
	printf("%s\n",strsignal(signum));
	execlp("ls","ls",NULL);
}
void (*orig_handler)(int);
int main(){
	orig_handler=signal(SIGUSR1,handler);
	if(orig_handler==SIG_ERR){
		perror("signal");
		exit(1);
	}
	pid_t pid=fork();
	if(pid==-1){
		perror("fork");
		exit(1);
	}
	if(pid==0){
		printf("pause");
		pause();	
		exit(0);
	}else{
		sleep(1);
		int ret=kill(pid,SIGUSR1);
		if(ret==-1){
			perror("kill");
			exit(1);
		}
		if(ret==0){
			printf("kill OK\n");
		}
		waitpid(pid,NULL,0);
		printf("waitpid OK\n");
	}
	signal(SIGUSR1,orig_handler);
	return 0;
}
